package com.nbsaas.boot.app.rest.convert;

import com.nbsaas.boot.app.api.domain.request.AppUserRoleRequest;
import com.nbsaas.boot.app.data.entity.App;
import com.nbsaas.boot.app.data.entity.AppRole;
import com.nbsaas.boot.app.data.entity.AppUserRole;
import com.nbsaas.boot.rest.api.Converter;
import com.nbsaas.boot.utils.BeanDataUtils;

/**
 * 应用用户角色请求对象转换成实体对象
 */

public class AppUserRoleEntityConvert implements Converter<AppUserRole, AppUserRoleRequest> {

    @Override
    public AppUserRole convert(AppUserRoleRequest source) {
        AppUserRole result = new AppUserRole();
        BeanDataUtils.copyProperties(source, result);
        if (source.getApp() != null) {
            App app = new App();
            app.setId(source.getApp());
            result.setApp(app);
        }
        if (source.getRole() != null) {
            AppRole role = new AppRole();
            role.setId(source.getRole());
            result.setRole(role);
        }
        return result;
    }
}

